home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Applications / Moscow ML 1.31 / source code / ANSIshellƒ / os_mac_eStyle.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-04  |  22.7 KB  |  801 lines  |  [TEXT/R*ch]

  1. /* os_mac_eStyle.c
  2.  * 2Jun92  e
  3.  */
  4.  
  5. #ifdef THINK_C
  6. #include <MacHeaders>
  7. #else
  8. #ifdef __MWERKS__
  9. #else
  10. "Unknown compiler!"
  11. #endif
  12. #endif
  13.  
  14. /*
  15. #include <Dialogs.h>
  16. #include <Controls.h>
  17. #include <QuickDraw.h>
  18. #include <Windows.h>
  19. #include <ToolUtils.h>
  20. #include <OSUtils.h>
  21. #include <Menus.h>
  22. #include <Fonts.h>
  23. #include <resources.h>
  24. */
  25.  
  26. #include "os_mac.h"
  27.  
  28. /* extensions to an editor for text files by e
  29.    questions/comments via Internet <e@Flavors.COM>
  30. */
  31. /* Copyright © e 1992. All rights reserved.
  32.     Developed using THINK C 5.0.1 for use with Gambit Scheme.
  33.     This code may be freely distributed as long as this notice remains.
  34. */
  35.  
  36. /* to do:
  37. 06Jun92  e
  38. consider checkbox to modify OK to:
  39. - Set Style for All Windows
  40. consider showing text in style
  41. - (let ((the 3) (quick 5) (brown 7)) (fox jumps over the lazy dog))
  42. - ((lambda (the quick brown) (fox jumps over (the lazy) dog)) 3 5 7)
  43. consider a way to save Window's style in the file
  44. consider a way to save Creation style (preferences)
  45. add a Use Outline Fonts checkbox
  46. */
  47.  
  48. #define MAXFONTSIZE 1023
  49.  
  50. /* resources */
  51.  
  52. #define esdID        357
  53.  
  54. /* dialog items */
  55.  
  56. #define esdOK         1
  57. #define esdCancel     2
  58. #define esdTabsEt     3
  59. #define esdTabsSt     4
  60. #define esdFont1St     5
  61. #define esdFont1Pu     6
  62. #define esdSize1St     7
  63. #define esdSize1Et     8
  64. #define esdBold1Cb     9
  65. #define esdItal1Cb    10
  66. #define esdCond1Cb    11
  67. #define esdUndr1Cb    12
  68. #define esdInvr1Cb    13
  69. #define esdExpd1Cb    14
  70. #define esdFont2St    15
  71. #define esdFont2Pu    16
  72. #define esdSize2St    17
  73. #define esdSize2Et    18
  74. #define esdBold2Cb    19
  75. #define esdItal2Cb    20
  76. #define esdCond2Cb    21
  77. #define esdUndr2Cb    22
  78. #define esdInvr2Cb    23
  79. #define esdExpd2Cb    24
  80. #define esdPS1St    25
  81. #define esdPS2St    26
  82. #define esdSize1Pu    27
  83. #define esdSize2Pu    28
  84. #define esdOutline1    29
  85. #define esdOutline2    30
  86. #define esdOKring    31
  87. #define esdThisBt    32
  88. #define esdPrefBt    33
  89. #define esdDfltBt    34
  90. #define esdGetSt    35
  91. #define esdOutline3    36
  92. #define esdApplSt    37
  93. #define esdThisCb    38
  94. #define esdPrefCb    39
  95. #define esdWrapEt    40
  96. #define esdAutoInd    42
  97.  
  98. /* the pop-up font item */
  99.  
  100. /* See: Apple Macintosh Developer Technical Support
  101.         Pop-up Menu Example Application
  102.         PopMenus.p
  103. */
  104.  
  105. static TextStyle tsNewPri, tsNewAlt;
  106. static short tabsNew;
  107. static short wrapNew;
  108. static short autoIndNew;
  109.  
  110. #define popMenuID1 128
  111. static MenuHandle popMenu1;
  112. static Rect  popUpBox1;        /* boundsrect of font popUp1 */
  113. static Rect  promptBox1;    /* boundsrect of its title */
  114. static short fontChoice1;    /* its last chosen item */
  115.  
  116. #define popMenuID2 129
  117. static MenuHandle popMenu2;
  118. static Rect  popUpBox2;        /* boundsrect of font popUp2 */
  119. static Rect  promptBox2;    /* boundsrect of its title */
  120. static short fontChoice2;    /* its last chosen item */
  121.  
  122. #define popMenuID3 130
  123. static MenuHandle popMenu3;
  124. static Rect  popUpBox3;        /* boundsrect of font popUp2 */
  125. static short sizeChoice3;    /* its last chosen item */
  126.  
  127. #define popMenuID4 131
  128. static MenuHandle popMenu4;
  129. static Rect  popUpBox4;        /* boundsrect of font popUp2 */
  130. static short sizeChoice4;    /* its last chosen item */
  131.  
  132. /* some user item action procs -- used in update events mostly */
  133.  
  134. #define leftSlop 15
  135. #define rightSlop 17
  136. #define botSlop 5
  137.  
  138. static void drawPopArrow( Rect r )
  139.   FrameRect( &r );
  140.   MoveTo( r.right, r.top+2 );
  141.   LineTo( r.right, r.bottom );
  142.   LineTo( r.left+2, r.bottom );
  143.   MoveTo( r.right-17, r.top+6 );
  144.   Line( 11, 0 );
  145.   Move( -10, 1 );
  146.   Line( 9, 0 );
  147.   Move( -8, 1);
  148.   Line( 7, 0 );
  149.   Move( -6, 1);
  150.   Line( 5, 0 );
  151.   Move( -4, 1 );
  152.   Line( 3, 0 );
  153.   Move( -2, 1 );
  154.   Line( 1, 0 );
  155. }
  156.  
  157. static pascal void DrawPopUpSz( DialogPtr dwind, short dinum )
  158. { short itemtype;
  159.   Handle itemhandle;
  160.   Rect r;
  161.   GetDItem( dwind, dinum, &itemtype, &itemhandle, &r );
  162.   InsetRect( &r, -1, -1 );
  163.   drawPopArrow( r );
  164. }
  165.  
  166. static void DrawPopUpX( MenuHandle popMenu, Rect* popUpBox, short lastChoice )
  167. { Rect r;
  168.   Str255 curFont;
  169.   short newWid, newLen, wid;
  170.  
  171.   GetItem( popMenu, lastChoice, curFont ); /* get currently-selected item */
  172.   r = *popUpBox;
  173.   EraseRect( &r );
  174.   InsetRect( &r, -1, -1 );
  175.   /* Make sure the title fits. Truncate it and add an ellipses (“…”) otherwise */
  176.   wid = (r.right - r.left) - (leftSlop + rightSlop);
  177.   newWid = StringWidth( curFont );
  178.   if( newWid > wid )
  179.   { newLen = curFont[0]; /* current length in characters */
  180.     wid = wid - CharWidth('…');
  181.     do
  182.     { newWid = newWid - CharWidth( curFont[newLen--] );
  183.     } while( ( newWid > wid ) && ( newLen > 0 ) );
  184.     curFont[++newLen] = '…';
  185.     curFont[0] = newLen;
  186.   }
  187.   drawPopArrow( r );
  188.   MoveTo( r.left+leftSlop, r.bottom-botSlop);
  189.   DrawString( curFont );
  190. }
  191.  
  192. static pascal void DrawPopUp1( DialogPtr theDialog, short theItem )
  193. { DrawPopUpX( popMenu1, &popUpBox1, fontChoice1 );
  194. }
  195.  
  196. static pascal void DrawPopUp2( DialogPtr theDialog, short theItem )
  197. { DrawPopUpX( popMenu2, &popUpBox2, fontChoice2 );
  198. }
  199.  
  200. /* BorderDefault draws a heavy border around the default ( OK ) button */
  201. static pascal void BorderDefault( WindowPtr dwind, short dinum )
  202. { short itemtype;
  203.   Handle itemhandle;
  204.   Rect borderRect;
  205.   GetDItem( dwind, esdOK, &itemtype, &itemhandle, &borderRect );
  206.   InsetRect( &borderRect, -4, -4 );
  207.   PenSize( 3, 3 );
  208.   FrameRoundRect( &borderRect, 16, 16 );
  209.   PenSize( 1, 1 );
  210. }
  211.  
  212. /* Outliner draws a light border around the the user item */
  213. static pascal void Outliner( WindowPtr dwind, short dinum )
  214. { short itemtype;
  215.   Handle itemhandle;
  216.   Rect borderRect;
  217.   GetDItem( dwind, dinum, &itemtype, &itemhandle, &borderRect );
  218.   /* InsetRect( &borderRect, -4, -4 ); */
  219.   PenSize( 1, 1 );
  220.   FrameRoundRect( &borderRect, 16, 16 );
  221. }
  222.  
  223. /* util fcns. */
  224.  
  225. /* cursor to IBeam if it's over an active edit line, arrow if it's not */
  226. void IBeamIt( WindowPtr dwind )
  227. { Point mouseAt;
  228.   short itemtype;
  229.   Handle itemhandle;
  230.   Rect borderRect;
  231.   short itemNum;
  232.   /* first get the current edit line out of the dialog record */
  233.   itemNum = ((DialogPeek )dwind)->editField + 1; /* always stored 1 less */
  234.   GetDItem( dwind, itemNum, &itemtype, &itemhandle, &borderRect );
  235.   GetMouse( &mouseAt );
  236.   if( PtInRect( mouseAt, &borderRect ) )
  237.     SetCursor(&ibeam_cursor);
  238.   else
  239.     SetCursor(&qd.arrow);
  240. }
  241.  
  242. static void pseudoClick( DialogPtr dbox, short item )
  243. { short itemtype;
  244.   Rect itemrect;
  245.   Handle hC;
  246.   long tilticks;
  247.   GetDItem( dbox, item, &itemtype, &hC, &itemrect );
  248.   HiliteControl( (ControlHandle)hC, inButton );
  249.   Delay( 8, &tilticks );
  250.   HiliteControl( (ControlHandle)hC, false );
  251. }
  252.  
  253. static short apndMenu( MenuHandle hM, Str255 title, short itemno, Boolean check, Boolean realfont )
  254. {
  255.   AppendMenu( hM, title );
  256.   if( realfont ) SetItemStyle( hM, itemno, outline );
  257.   if( check )
  258.   { SetItemMark( hM, itemno, checkMark );
  259.     return itemno;
  260.   }
  261.   return 0;
  262. }
  263.  
  264. static MenuHandle sizeMenu( short id, short *ckitem, short fNum, short curSize )
  265. { MenuHandle hM;
  266.   Str255 oddSize;
  267.   short match = 0;
  268.   hM = NewMenu( id, "\p" );
  269.   match |= apndMenu( hM,  "\p9", 1, (curSize ==  9), RealFont( fNum,  9 ) );
  270.   match |= apndMenu( hM, "\p10", 2, (curSize == 10), RealFont( fNum, 10 ) );
  271.   match |= apndMenu( hM, "\p12", 3, (curSize == 12), RealFont( fNum, 12 ) );
  272.   match |= apndMenu( hM, "\p14", 4, (curSize == 14), RealFont( fNum, 14 ) );
  273.   match |= apndMenu( hM, "\p18", 5, (curSize == 18), RealFont( fNum, 18 ) );
  274.   match |= apndMenu( hM, "\p24", 6, (curSize == 24), RealFont( fNum, 24 ) );
  275.   if( match == 0 )
  276.   { NumToString( (long )curSize, oddSize );
  277.     InsMenuItem( hM, oddSize, 0 );
  278.     InsMenuItem( hM, "\p(-", 1 );
  279.     SetItemMark( hM, 1, checkMark );
  280.     if( RealFont( fNum, curSize ) ) SetItemStyle( hM, 1, outline );
  281.     *ckitem = 1;
  282.   }
  283.   else *ckitem = match;
  284.   return( hM );
  285. }
  286.  
  287. static short doPop( DialogPtr esd, MenuHandle popMenu, Rect popUpBox, short id, short oldChoice )
  288. { long chosen;
  289.   Point popLoc;
  290.   short newChoice;
  291.   InsertMenu( popMenu, -1 );
  292.   popLoc = topLeft(popUpBox);
  293.   LocalToGlobal( &popLoc );
  294.   CalcMenuSize( popMenu ); /* Work around Menu Mgr bug */
  295.   chosen = PopUpMenuSelect( popMenu, popLoc.v, popLoc.h, oldChoice );
  296.   DeleteMenu( id );
  297.   if( chosen != 0 )
  298.   { newChoice = LoWord(chosen);
  299.     if( newChoice != oldChoice )
  300.     { SetItemMark( popMenu, oldChoice, ' ' );
  301.       SetItemMark( popMenu, newChoice, checkMark );
  302.       EraseRect( &popUpBox );
  303.       return( newChoice );
  304.     }
  305.   }
  306.   return 0;
  307. }
  308.  
  309. /* filter proc */
  310.  
  311. #define kReturnKey 0x0D
  312. #define kEnterKey 0x03
  313. #define kEscKey 0x1B
  314. #define kTabKey 9
  315. enum  {
  316.     kBackSpace = 8,
  317.     kLeftArrow = 0x1C, kRightArrow, kUpArrow, kDownArrow,
  318.     kDeleteKey = 0x7F
  319. };
  320.  
  321. /* size menu selection => edit text box */
  322. static void doSize1( DialogPtr esd )
  323. { Rect tempRect;
  324.   short tempItem;
  325.   Handle tempHandle;
  326.   long tmp;
  327.   Str255 tStr;
  328.   GetDItem( esd, esdSize1Et, &tempItem, &tempHandle, &tempRect );
  329.   GetItem( popMenu3, sizeChoice3, tStr );
  330.   SetIText( tempHandle, tStr );
  331.   SelIText( esd, esdSize1Et, 0, 32767 );
  332.   StringToNum( tStr, &tmp);
  333.   tsNewPri.tsSize = tmp;
  334. }
  335.  
  336. /* size menu selection => edit text box */
  337. static void doSize2( DialogPtr esd )
  338. { Rect tempRect;
  339.   short tempItem;
  340.   Handle tempHandle;
  341.   long tmp;
  342.   Str255 tStr;
  343.   GetDItem( esd, esdSize2Et, &tempItem, &tempHandle, &tempRect );
  344.   GetItem( popMenu4, sizeChoice4, tStr );
  345.   SetIText( tempHandle, tStr );
  346.   SelIText( esd, esdSize2Et, 0, 32767 );
  347.   StringToNum( tStr, &tmp);
  348.   tsNewAlt.tsSize = tmp;
  349. }
  350.  
  351. /* font menu selection triggers update of size menu */
  352. static void doFont1( void )
  353. { Str255 tStr;
  354.   GetItem( popMenu1, fontChoice1, tStr );
  355.   GetFNum( tStr, &tsNewPri.tsFont );
  356.   if( popMenu3 ) DisposHandle( (Handle )popMenu3 );
  357.   popMenu3 = sizeMenu( popMenuID3, &sizeChoice3, tsNewPri.tsFont, tsNewPri.tsSize );
  358. }
  359.  
  360. /* font menu selection triggers update of size menu */
  361. static void doFont2( void )
  362. { Str255 tStr;
  363.   GetItem( popMenu2, fontChoice2, tStr );
  364.   GetFNum( tStr, &tsNewAlt.tsFont );
  365.   if( popMenu4 ) DisposHandle( (Handle )popMenu4 );
  366.   popMenu4 = sizeMenu( popMenuID4, &sizeChoice4, tsNewAlt.tsFont, tsNewAlt.tsSize );
  367. }
  368.  
  369. /* this function always returns a value between 1 and MAXFONTSIZE inclusive */
  370. /* an out of range number returns 8;
  371.    this is so font sizes and tab stops are reasonable */
  372. static long etToNum( DialogPtr dbox, short item )
  373. { short tempItem;
  374.   Rect tempRect;
  375.   Handle tempHandle;
  376.   long tmp;
  377.   Str255 tStr;
  378.   GetDItem( dbox, item, &tempItem, &tempHandle, &tempRect );
  379.   GetIText( tempHandle, tStr );
  380.   StringToNum( tStr, &tmp);
  381.   if( tmp > MAXFONTSIZE || tmp < 1 ) tmp = 8;
  382.   return tmp;
  383. }
  384.  
  385. /* update size menu if size edit text box changed */
  386. static void preSize1( DialogPtr esd )
  387. { long tmp;
  388.   tmp = etToNum( esd, esdSize1Et );
  389.   if( tsNewPri.tsSize != tmp )
  390.   { tsNewPri.tsSize = tmp;
  391.     if( popMenu3 ) DisposHandle( (Handle )popMenu3 );
  392.     popMenu3 = sizeMenu( popMenuID3, &sizeChoice3, tsNewPri.tsFont, tsNewPri.tsSize );
  393.   }
  394. }
  395.  
  396. /* update size menu if size edit text box changed */
  397. static void preSize2( DialogPtr esd )
  398. { long tmp;
  399.   tmp = etToNum( esd, esdSize2Et );
  400.   if( tsNewAlt.tsSize != tmp )
  401.   { tsNewAlt.tsSize = tmp;
  402.     if( popMenu4 ) DisposHandle( (Handle )popMenu4 );
  403.     popMenu4 = sizeMenu( popMenuID4, &sizeChoice4, tsNewAlt.tsFont, tsNewAlt.tsSize );
  404.   }
  405. }
  406.  
  407. pascal Boolean filterIt( DialogPtr esd, EventRecord *myDialogEvent, short *theDialogItem)
  408. { WindowPtr temp;
  409.   char theKey;
  410.   Rect tempRect;
  411.   short tempItem;
  412.   Handle tempHandle;
  413.   Boolean result = false;
  414.  
  415.   GetPort( &temp );
  416.   SetPort( esd );
  417.     
  418.   IBeamIt( esd ); /* make IBeam cursor when over the active edit line */
  419.     
  420.   /* do standard filtering for escape and return as OK and Cancel aliases */
  421.   /* invert the button in the dialog, so the user get's visual feedback */
  422.  
  423.   if ((myDialogEvent->what == keyDown) || (myDialogEvent->what == autoKey))
  424.   { theKey = myDialogEvent->message & charCodeMask;
  425.     if( (myDialogEvent->modifiers & (cmdKey|controlKey|optionKey)) == 0 )
  426.     { switch( theKey )
  427.       { case kReturnKey:
  428.         case kEnterKey:
  429.             *theDialogItem = esdOK;
  430.             pseudoClick( esd, esdOK );
  431.           SetPort(temp);
  432.           result = true;
  433.           break;
  434.         case kEscKey:
  435.           *theDialogItem = esdCancel;
  436.           pseudoClick( esd, esdCancel );
  437.           SetPort(temp);
  438.           result = true;
  439.           break;
  440.         case kTabKey:
  441.         case kBackSpace:
  442.         case kLeftArrow:
  443.         case kRightArrow:
  444.         case kUpArrow:
  445.         case kDownArrow:
  446.         case kDeleteKey:
  447.             break;
  448.         default:
  449.           /* filter out non-numeric keys */
  450.           if( theKey < 0x30 || theKey > 0x39 )
  451.           { SysBeep( 1 );
  452.             SetPort( temp );
  453.             result = true;
  454.           }
  455.           break;
  456.       }
  457.     }
  458.   }
  459.   else if( myDialogEvent->what == mouseDown )
  460.   { Point mouseLoc;
  461.     short newChoice;
  462.     mouseLoc = ( myDialogEvent->where );
  463.     GlobalToLocal( &mouseLoc );
  464.     switch( newChoice = FindDItem( esd, mouseLoc ) + 1 )
  465.     { case esdFont1St:
  466.       case esdFont1Pu:
  467.         InvertRect( &promptBox1 );
  468.         newChoice = doPop( esd, popMenu1, popUpBox1, popMenuID1, fontChoice1 );
  469.         InvertRect( &promptBox1 );
  470.         if( newChoice != 0 )
  471.         { fontChoice1 = newChoice;
  472.           DrawPopUp1( esd, esdFont1Pu );
  473.           *theDialogItem = esdFont1Pu;
  474.           SetPort( temp );
  475.           result = true;
  476.         }
  477.         break;
  478.       case esdFont2St:
  479.       case esdFont2Pu:
  480.         InvertRect( &promptBox2 );
  481.         newChoice = doPop( esd, popMenu2, popUpBox2, popMenuID2, fontChoice2 );
  482.         InvertRect( &promptBox2 );
  483.         if( newChoice != 0 )
  484.         { fontChoice2 = newChoice;
  485.           DrawPopUp2( esd, esdFont2Pu );
  486.           *theDialogItem = esdFont2Pu;
  487.           SetPort( temp );
  488.           result = true;
  489.         }
  490.         break;
  491.       /* case esdSize2St:  not for size menu!? */
  492.       case esdSize1Pu:
  493.           SelIText( esd, esdSize1Et, 0, 32767 );
  494.           preSize1( esd );
  495.         newChoice = doPop( esd, popMenu3, popUpBox3, popMenuID3, sizeChoice3 );
  496.         if( newChoice != 0 )
  497.         { sizeChoice3 = newChoice;
  498.           DrawPopUpSz( esd, esdSize1Pu );
  499.           *theDialogItem = esdSize1Pu;
  500.           SetPort( temp );
  501.           result = true;
  502.         }
  503.         break;
  504.       /* case esdSize2St:  not for size menu!? */
  505.       case esdSize2Pu:
  506.           SelIText( esd, esdSize2Et, 0, 32767 );
  507.           preSize2( esd );
  508.         newChoice = doPop( esd, popMenu4, popUpBox4, popMenuID4, sizeChoice4 );
  509.         if( newChoice != 0 )
  510.         { sizeChoice4 = newChoice;
  511.           DrawPopUpSz( esd, esdSize2Pu );
  512.           *theDialogItem = esdSize2Pu;
  513.           SetPort( temp );
  514.           result = true;
  515.         }
  516.         break;
  517.     }
  518.   }
  519.   return( result );
  520. }
  521.  
  522. static void check( DialogPtr dbox, short item, Boolean mark )
  523. { ControlHandle hC;
  524.   short itemtype;
  525.   Rect itemrect;    
  526.   GetDItem( dbox, item, &itemtype, (Handle *)&hC, &itemrect);
  527.   SetCtlValue( hC, mark );
  528. }
  529.  
  530. static void checks( DialogPtr dbox, short style, short offs )
  531. {
  532.   check( dbox, esdBold1Cb + offs, ( style & bold ) ? 1 : 0 );
  533.   check( dbox, esdItal1Cb + offs, ( style & italic ) ? 1 : 0 );
  534.   check( dbox, esdUndr1Cb + offs, ( style & underline ) ? 1 : 0 );
  535.   check( dbox, esdCond1Cb + offs, ( style & condense ) ? 1 : 0 );
  536.   check( dbox, esdExpd1Cb + offs, ( style & extend ) ? 1 : 0 );
  537.   /*
  538.   check( dbox, esdInvr1Cb + offs, ( style & bold ) ? 1 : 0 );
  539.   */
  540. }
  541.  
  542. short checklist[] = { bold, italic, condense, underline, 0x80, extend };
  543.  
  544. static short findFontItem( MenuHandle hM, short fontNum )
  545. { short result = 1;
  546.   short i, fn;
  547.   Str255 tStr;
  548.   for( i = CountMItems( hM ); i > 0; i-- )
  549.   { GetItem( hM, i, tStr );
  550.     GetFNum( tStr, &fn );
  551.     if( fn == fontNum ) return i;
  552.     if( fn == 0 ) result = i;
  553.   }
  554.   return result;
  555. }
  556.  
  557. /* get the item's rect & set the procPtr */
  558. static void initUserItem( DialogPtr esd, short item, Rect *pRect, UserItemUPP pProc )
  559. { short tempItem;
  560.   Handle tempHandle;
  561.   GetDItem( esd, item, &tempItem, &tempHandle, pRect );
  562.   SetDItem( esd, item, tempItem, (Handle )pProc, pRect );
  563. }
  564.  
  565. static void hosePops( void )
  566. {
  567.   if( popMenu1 ) DisposHandle( (Handle )popMenu1 );
  568.   popMenu1 = 0;
  569.   if( popMenu2 ) DisposHandle( (Handle )popMenu2 );
  570.   popMenu2 = 0;
  571.   if( popMenu3 ) DisposHandle( (Handle )popMenu3 );
  572.   popMenu3 = 0;
  573.   if( popMenu4 ) DisposHandle( (Handle )popMenu4 );
  574.   popMenu4 = 0;
  575. }
  576.  
  577. static void initPops( DialogPtr esd )
  578. { Str255 tStr;
  579.   short tempItem;
  580.   Rect tempRect;
  581.   Handle tempHandle;
  582.  
  583.   hosePops();
  584.   
  585.   SetPort( esd );
  586.   
  587.   popMenu1 = NewMenu( popMenuID1, "\p" );
  588.   AddResMenu( popMenu1, 'FONT' );
  589.   fontChoice1 = findFontItem( popMenu1, tsNewPri.tsFont );
  590.   SetItemMark( popMenu1, fontChoice1, checkMark );
  591.   InvalRect( &popUpBox1 );
  592.     
  593.   popMenu2 = NewMenu( popMenuID2, "\p" );
  594.   AddResMenu( popMenu2, 'FONT' );
  595.   fontChoice2 = findFontItem( popMenu2, tsNewAlt.tsFont );
  596.   SetItemMark( popMenu2, fontChoice2, checkMark );
  597.   InvalRect( &popUpBox2 );
  598.   
  599.   popMenu3 = sizeMenu( popMenuID3, &sizeChoice3, tsNewPri.tsFont, tsNewPri.tsSize );
  600.   doSize1( esd );
  601.  
  602.   popMenu4 = sizeMenu( popMenuID4, &sizeChoice4, tsNewAlt.tsFont, tsNewAlt.tsSize );
  603.   doSize2( esd );
  604.   
  605.   checks( esd, tsNewPri.tsFace,  0 );
  606.   checks( esd, tsNewAlt.tsFace, 10 );
  607.   
  608.   NumToString( (long )tabsNew, tStr );
  609.   GetDItem( esd, esdTabsEt, &tempItem, &tempHandle, &tempRect );
  610.   SetIText( tempHandle, tStr );
  611.   SelIText( esd, esdTabsEt, 0, 32767 );
  612.   
  613.   NumToString( (long )wrapNew, tStr );
  614.   GetDItem( esd, esdWrapEt, &tempItem, &tempHandle, &tempRect );
  615.   SetIText( tempHandle, tStr );
  616.   SelIText( esd, esdWrapEt, 0, 32767 );
  617.  
  618.   check( esd, esdAutoInd, autoIndNew );
  619. }
  620.  
  621. static suppinit = 0;
  622. ModalFilterUPP filterItUPP;
  623. UserItemUPP DrawPopUp1UPP;
  624. UserItemUPP DrawPopUp2UPP;
  625. UserItemUPP DrawPopUpSzUPP;
  626. UserItemUPP OutlinerUPP;
  627. UserItemUPP BorderDefaultUPP;
  628.  
  629. void eStyleDlg( eRec **hE /* , TextStyle *pri, TextStyle *alt */ )
  630. { DialogPtr esd = NULL;
  631.   short hitItem = 0;
  632.   short tempItem;
  633.   Rect tempRect;
  634.   Handle tempHandle;
  635.   Boolean tBool;
  636.   long tmp1, tmp2, tmp3;
  637.  
  638.   if ( ! suppinit )
  639.   { filterItUPP = NewModalFilterProc(filterIt);
  640.     DrawPopUp1UPP  = NewUserItemProc(DrawPopUp1);
  641.     DrawPopUp2UPP  = NewUserItemProc(DrawPopUp2);
  642.     DrawPopUpSzUPP = NewUserItemProc(DrawPopUpSz);
  643.     OutlinerUPP    = NewUserItemProc(Outliner);
  644.     BorderDefaultUPP = NewUserItemProc(BorderDefault);
  645.     suppinit = 1;
  646.   }
  647.   
  648.   tsNewPri = (**hE).style[0];
  649.   tsNewAlt = (**hE).style[1];
  650.   tabsNew = (**hE).tabStops;
  651.   wrapNew = (**hE).wrap;
  652.   autoIndNew = (**hE).autoInd;
  653.  
  654.   /* Get a dialog box, and set up our useritems */
  655.   esd = GetNewDialog( esdID, NULL, (WindowPtr)(-1) );
  656.         
  657.   /* Find out where our useritems are, and set their item handles to be
  658.      a pointer to our popup-drawing or other special procedure */
  659.   GetDItem( esd, esdFont1St, &tempItem, &tempHandle, &promptBox1 ); /* get the title rect */
  660.   initUserItem( esd, esdFont1Pu, &popUpBox1, DrawPopUp1UPP ); /* universal header kludge 7Jun94 e */
  661.   GetDItem( esd, esdFont2St, &tempItem, &tempHandle, &promptBox2 ); /* get the title rect */
  662.   initUserItem( esd, esdFont2Pu, &popUpBox2, DrawPopUp2UPP ); /* universal header kludge 7Jun94 e */
  663.   initUserItem( esd, esdSize1Pu, &popUpBox3, DrawPopUpSzUPP ); /* universal header kludge 7Jun94 e */
  664.   initUserItem( esd, esdSize2Pu, &popUpBox4, DrawPopUpSzUPP ); /* universal header kludge 7Jun94 e */
  665.   initUserItem( esd, esdOutline1, &tempRect, OutlinerUPP ); /* universal header kludge 7Jun94 e */
  666.   initUserItem( esd, esdOutline2, &tempRect, OutlinerUPP ); /* universal header kludge 7Jun94 e */
  667.   initUserItem( esd, esdOutline3, &tempRect, OutlinerUPP ); /* universal header kludge 7Jun94 e */
  668.  
  669.   GetDItem( esd, esdOK,&tempItem, &tempHandle, &tempRect ); /* get the OK button's rect */
  670.   InsetRect( &tempRect, -4, -4);
  671.   SetDItem( esd, esdOKring, userItem+itemDisable, (Handle )BorderDefaultUPP, &tempRect);
  672.  
  673.   /* Get two menus containing the current set of fonts */
  674.   /* and two menus containing their corresponding sizes */
  675.   initPops( esd );
  676.   
  677.   check( esd, esdThisCb, 1 );
  678.   check( esd, esdPrefCb, 0 );    /* defaulted to off  --  16Jul92  e  */
  679.     
  680.   ShowWindow( (WindowPtr)esd );
  681.   DrawDialog( esd );
  682.   do
  683.   { ModalDialog( filterItUPP, &hitItem );
  684.     switch ( hitItem )
  685.     { case esdFont1Pu:
  686.         doFont1( );
  687.         break;
  688.       case esdFont2Pu:
  689.         doFont2( );
  690.         break;
  691.       case esdSize1Pu:
  692.           doSize1( esd );
  693.         break;
  694.       case esdSize2Pu:
  695.           doSize2( esd );
  696.         break;
  697.       case esdBold1Cb:
  698.       case esdItal1Cb:
  699.       case esdCond1Cb:
  700.       case esdUndr1Cb:
  701.       case esdInvr1Cb:
  702.       case esdExpd1Cb:
  703.         GetDItem( esd, hitItem, &tempItem, &tempHandle, &tempRect);
  704.         tempItem = GetCtlValue( (ControlHandle )tempHandle ) ^ 1;
  705.         if( tempItem == 0 )
  706.           tsNewPri.tsFace &= ~checklist[hitItem-esdBold1Cb];
  707.         else
  708.           tsNewPri.tsFace |=  checklist[hitItem-esdBold1Cb];
  709.         SetCtlValue( (ControlHandle )tempHandle, tempItem);
  710.         break;
  711.       case esdBold2Cb:
  712.       case esdItal2Cb:
  713.       case esdCond2Cb:
  714.       case esdUndr2Cb:
  715.       case esdInvr2Cb:
  716.       case esdExpd2Cb:
  717.         GetDItem( esd, hitItem, &tempItem, &tempHandle, &tempRect);
  718.         tempItem = GetCtlValue( (ControlHandle )tempHandle ) ^ 1;
  719.         if( tempItem == 0 )
  720.           tsNewAlt.tsFace &= ~checklist[hitItem-esdBold2Cb];
  721.         else
  722.           tsNewAlt.tsFace |=  checklist[hitItem-esdBold2Cb];
  723.         SetCtlValue( (ControlHandle )tempHandle, tempItem);
  724.         break;
  725.       case esdThisCb:
  726.       case esdPrefCb:
  727.       case esdAutoInd:
  728.         GetDItem( esd, hitItem, &tempItem, &tempHandle, &tempRect);
  729.         tempItem = GetCtlValue( (ControlHandle )tempHandle ) ^ 1;
  730.         SetCtlValue( (ControlHandle )tempHandle, tempItem);
  731.         break;
  732.       case esdThisBt:
  733.         tsNewPri = (**hE).style[0];
  734.         tsNewAlt = (**hE).style[1];
  735.         tabsNew =  (**hE).tabStops;
  736.         wrapNew =  (**hE).wrap;
  737.         autoIndNew = (**hE).autoInd;
  738.         initPops( esd );
  739.         break;
  740.       case esdPrefBt:
  741.         tsNewPri = prefStylNormal;
  742.         tsNewAlt = prefStylHilite;
  743.         tabsNew  = prefTabs;
  744.         wrapNew  = prefWrap;
  745.         autoIndNew = prefAutoInd;
  746.         initPops( esd );
  747.         break;
  748.       case esdDfltBt:
  749.         tsNewPri = dfltStylNormal;
  750.         tsNewAlt = dfltStylHilite;
  751.         tabsNew  = dfltTabs;
  752.         wrapNew  = dfltWrap;
  753.         autoIndNew = dfltAutoInd;
  754.         initPops( esd );
  755.         break;
  756.     }
  757.   } while ( hitItem != esdOK && hitItem != esdCancel );
  758.   
  759.   if( hitItem == esdOK )
  760.   { tsNewPri.tsSize = etToNum( esd, esdSize1Et );
  761.     tsNewAlt.tsSize = etToNum( esd, esdSize2Et );
  762.     tmp1 = etToNum( esd, esdTabsEt );
  763.     tmp2 = etToNum( esd, esdWrapEt );
  764.     GetDItem( esd, esdAutoInd, &tempItem, &tempHandle, &tempRect);
  765.     tmp3 = GetCtlValue( (ControlHandle )tempHandle );
  766.     GetDItem( esd, esdThisCb, &tempItem, &tempHandle, &tempRect);
  767.     if( GetCtlValue( (ControlHandle )tempHandle ) )
  768.     { if( (**hE).tabStops != tmp1 )
  769.       { eTeSetTabStop( hE, (short )tmp1 );
  770.       }
  771.       if( (**hE).wrap != tmp2 )
  772.       { eTeSetWrap( hE, (short )tmp2 );
  773.       }
  774.       (**hE).autoInd = tmp3;
  775.       if(    tsNewPri.tsFont != (**hE).style[0].tsFont
  776.           || tsNewPri.tsSize != (**hE).style[0].tsSize
  777.           || tsNewPri.tsFace != (**hE).style[0].tsFace
  778.           || tsNewAlt.tsFont != (**hE).style[1].tsFont
  779.           || tsNewAlt.tsSize != (**hE).style[1].tsSize
  780.           || tsNewAlt.tsFace != (**hE).style[1].tsFace
  781.         )
  782.       { eTeSetStyles( hE, &tsNewPri, &tsNewAlt );
  783.       }
  784.     }
  785.     GetDItem( esd, esdPrefCb, &tempItem, &tempHandle, &tempRect);
  786.     if( GetCtlValue( (ControlHandle )tempHandle ) )
  787.     { prefStylNormal = tsNewPri;
  788.       prefStylHilite = tsNewAlt;
  789.       prefTabs    = (short )tmp1;
  790.       prefWrap    = (short )tmp2;
  791.       prefAutoInd = (short )tmp3;
  792.       savePrefs( PREFS_FILENAME );  /*  16Jul92  e  */
  793.     }
  794.   }
  795.   hosePops();
  796.   if( esd ) DisposDialog( esd );
  797. }
  798.  
  799. /* end of os_mac_eStyle.c */
  800.